// pages/my/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName:'',
    avatarUrl:'http://img2.imgtn.bdimg.com/it/u=164802939,3427154249&fm=27&gp=0.jpg'
  },
  onLoad(){
    const vm = this;
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        vm.setData({ userName: res.data.username })
      },
      fail() {
        wx.reLaunch({
          url: '/pages/login/index',
        })
      }
    })

    wx.getUserInfo({
      success: function(res){
        // console.log(res);
        vm.setData({
          avatarUrl:res.userInfo.avatarUrl
        })
      },
      fail: function(err) {
        console.log(err);
      }
    })
  },
  getUserInfoSD(res){
    // console.log(res.detail.userInfo.avatarUrl);
    this.setData({
      avatarUrl:res.detail.userInfo.avatarUrl
    })
  },
  siguOut(){
    wx.showModal({
      title: '系统提示',
      content: '确定退出？',
      success(res){
        console.log(res)
        if(res.confirm){
          wx.getSavedFileList({success(list){
            list.fileList.forEach(element => {
              wx.removeSavedFile({
                filePath:element.filePath,
                success(){
                  console.log(element.filePath);
                }
              })
            });
          }})

          
          wx.clearStorage({
            success: function (res) {
              wx.reLaunch({
                url: '/pages/login/index',
              })
            },
            fail(e){
              console.log(e)
            }
          })
          // return;
          /* wx.removeStorage({
            key: 'userInfo',
            success: function (res) {
              wx.reLaunch({
                url: '/pages/login/index',
              })
            }
          }) */
        }else if(res.cancel){
          console.log('取消')
        }
      }
    })
  },
  goRecords(){
    wx.navigateTo({url: '/pages/records/index'})
  },
  goColl(){
    wx.navigateTo({url: '/pages/collection/index'})
  }
})